{
  "name": "Case 53: Employee Benefit Claim Auditor - Intelligent Agent",
  "nodes": [
    {
      "parameters": {
        "path": "claim-submission-form",
        "formTitle": "Employee Benefit Claim Submission",
        "formDescription": "Submit your benefit claim with supporting receipts",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Upload Claim Form & Receipts",
              "fieldType": "file",
              "requiredField": true
            }
          ]
        },
        "options": {}
      },
      "id": "538dd424-f747-4a2f-a732-553e281b8177",
      "name": "Claim Submission Form",
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.1,
      "position": [
        -1280,
        -64
      ],
      "webhookId": "claim-submission-form"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.cloud.llamaindex.ai/api/v1/parsing/upload",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "sendBody": true,
        "contentType": "multipart-form-data",
        "bodyParameters": {
          "parameters": [
            {
              "parameterType": "formBinaryData",
              "name": "file",
              "inputDataFieldName": "Upload_Claim_Form___Receipts"
            }
          ]
        },
        "options": {}
      },
      "id": "22e249b0-3031-445d-8abd-b333beb7f8a5",
      "name": "Upload Claim Document",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -1072,
        -64
      ]
    },
    {
      "parameters": {
        "amount": 20
      },
      "id": "e7f33178-891f-4788-b0b5-b6cf5da37106",
      "name": "Wait for Parsing",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        -880,
        -64
      ],
      "webhookId": "5af21623-a8d6-4eaa-9fc1-64851fa01a74"
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload Claim Document\"].json[\"id\"] }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "97acef6c-c427-44ca-9a57-5453b09974a9",
      "name": "Check Parsing Status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -672,
        -64
      ]
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "SUCCESS",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "SUCCESS"
            },
            {
              "conditions": {
                "conditions": [
                  {
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "PENDING",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    }
                  }
                ]
              },
              "renameOutput": true,
              "outputKey": "PENDING"
            }
          ]
        },
        "options": {}
      },
      "id": "ac6493e9-d188-4dcd-a078-bf8a1af69af5",
      "name": "Status Router",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [
        -480,
        -64
      ]
    },
    {
      "parameters": {
        "url": "=https://api.cloud.llamaindex.ai/api/v1/parsing/job/{{ $node[\"Upload Claim Document\"].json[\"id\"] }}/result/markdown",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer llx-7BWYrvPwfUhgdXbZMtaNCsr2O0h7JH4dkHjHisxcvq46bkIj"
            }
          ]
        },
        "options": {}
      },
      "id": "d380d766-b3da-477b-8b0f-29350f580bcc",
      "name": "Get Parsed Claim Data",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.3,
      "position": [
        -272,
        -160
      ]
    },
    {
      "parameters": {
        "text": "={{ $json.markdown }}",
        "attributes": {
          "attributes": [
            {
              "name": "Employee_Name",
              "description": "Full name of employee"
            },
            {
              "name": "Employee_ID",
              "description": "Employee identifier"
            },
            {
              "name": "Department",
              "description": "Department name"
            },
            {
              "name": "Employee_Email",
              "description": "Employee email address"
            },
            {
              "name": "Contact_Number",
              "description": "Phone number"
            },
            {
              "name": "Claim_Type",
              "description": "Medical / Dental / Optical / Wellness / Education"
            },
            {
              "name": "Treatment_Date",
              "description": "Date of treatment in YYYY-MM-DD"
            },
            {
              "name": "Submission_Date",
              "description": "Date claim submitted in YYYY-MM-DD"
            },
            {
              "name": "Hospital_Clinic_Name",
              "description": "Name of medical facility"
            },
            {
              "name": "Doctor_Name",
              "description": "Name of treating doctor"
            },
            {
              "name": "Patient_Name",
              "description": "Who received treatment"
            },
            {
              "name": "Relationship_To_Employee",
              "description": "Self / Spouse / Child / Parent"
            },
            {
              "name": "Reason_For_Treatment",
              "description": "Brief description of treatment"
            },
            {
              "name": "Total_Claimed_Amount",
              "description": "Total amount claimed (numeric only, no currency)"
            },
            {
              "name": "Number_Of_Receipts",
              "description": "How many receipts attached (integer)"
            }
          ]
        },
        "options": {}
      },
      "id": "3d6ee07b-1713-475f-9bdd-27417c08d63a",
      "name": "Extract Claim Data",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [
        -32,
        -160
      ]
    },
    {
      "parameters": {
        "jsCode": "const extracted = $node[\"Extract Claim Data\"].json.output || {};\nconst formData = $node[\"Claim Submission Form\"].json || {};\n\n// ===== COMPANY POLICY RULES (HARDCODED) =====\n\nconst POLICY_RULES = {\n  Medical: { perClaimLimit: 2500, submissionWindowDays: 30 },\n  Dental: { perClaimLimit: 1500, submissionWindowDays: 30 },\n  Optical: { perClaimLimit: 3000, submissionWindowDays: 60 },\n  Wellness: { perClaimLimit: 2000, submissionWindowDays: 90 },\n  Education: { perClaimLimit: 5000, submissionWindowDays: 60 }\n};\n\nconst FRAUD_THRESHOLDS = {\n  highAmountFlag: 5000,\n  lateSubmissionDays: 25,\n  suspiciousRoundAmount: true\n};\n\n// ===== EXTRACT AND PARSE DATA =====\n\nconst claimType = extracted.Claim_Type || 'Medical';\nconst claimAmount = parseFloat(extracted.Total_Claimed_Amount || 0);\nconst treatmentDate = extracted.Treatment_Date || '';\nconst submissionDate = extracted.Submission_Date || new Date().toISOString().split('T')[0];\n\n// Get policy limits for this claim type\nconst policy = POLICY_RULES[claimType] || POLICY_RULES.Medical;\nconst perClaimLimit = policy.perClaimLimit;\nconst submissionWindowDays = policy.submissionWindowDays;\n\n// ===== CALCULATE COMPLIANCE =====\n\n// Calculate days between treatment and submission\nlet daysToSubmit = 0;\nif (treatmentDate && submissionDate) {\n  const treat = new Date(treatmentDate);\n  const submit = new Date(submissionDate);\n  daysToSubmit = Math.floor((submit - treat) / (1000 * 60 * 60 * 24));\n}\n\n// Check if within submission window\nconst withinWindow = daysToSubmit <= submissionWindowDays;\n\n// Calculate amount over limit\nconst amountOverLimit = Math.max(0, claimAmount - perClaimLimit);\nconst withinLimit = amountOverLimit === 0;\n\n// ===== FRAUD RISK SCORING =====\n\nlet fraudScore = 0;\n\n// 1. Amount exceeds policy limit (40 points)\nif (amountOverLimit > 0) {\n  if (amountOverLimit > perClaimLimit * 0.5) {\n    fraudScore += 40;\n  } else {\n    fraudScore += 20;\n  }\n}\n\n// 2. High amount flag (20 points)\nif (claimAmount >= FRAUD_THRESHOLDS.highAmountFlag) {\n  fraudScore += 20;\n}\n\n// 3. Late submission (15 points)\nif (daysToSubmit > FRAUD_THRESHOLDS.lateSubmissionDays) {\n  fraudScore += 15;\n}\n\n// 4. Suspicious round amounts (10 points)\nconst isRoundAmount = claimAmount % 1000 === 0 && claimAmount >= 3000;\nif (isRoundAmount) {\n  fraudScore += 10;\n}\n\n// 5. Missing receipts (15 points)\nconst receiptCount = parseInt(extracted.Number_Of_Receipts || 0);\nif (receiptCount === 0) {\n  fraudScore += 15;\n}\n\n// Cap at 100\nfraudScore = Math.min(fraudScore, 100);\n\n// ===== POLICY COMPLIANCE STATUS =====\n\nlet policyCompliance = 'COMPLIANT';\nif (amountOverLimit > 0) {\n  policyCompliance = 'EXCEEDS_LIMIT';\n} else if (!withinWindow) {\n  policyCompliance = 'LATE_SUBMISSION';\n} else if (receiptCount === 0) {\n  policyCompliance = 'MISSING_RECEIPTS';\n}\n\n// ===== DECISION LOGIC =====\n\nlet decision = '';\nlet approvedAmount = 0;\nlet nextAction = '';\n\nif (fraudScore >= 60) {\n  decision = 'REVIEW_REQUIRED';\n  approvedAmount = 0;\n  nextAction = 'High risk indicators detected. Route to HR compliance team for detailed verification.';\n} else if (amountOverLimit > 0) {\n  decision = 'PARTIAL_APPROVAL';\n  approvedAmount = perClaimLimit;\n  nextAction = `Approve ₹${perClaimLimit.toFixed(2)} (policy limit). Reject ₹${amountOverLimit.toFixed(2)} over limit. Employee can resubmit excess in next period.`;\n} else if (!withinWindow) {\n  decision = 'REVIEW_REQUIRED';\n  approvedAmount = 0;\n  nextAction = `Submitted ${daysToSubmit} days after treatment (policy: ${submissionWindowDays} days). Route to manager for exception approval.`;\n} else if (fraudScore >= 30) {\n  decision = 'REVIEW_REQUIRED';\n  approvedAmount = 0;\n  nextAction = 'Moderate risk indicators detected. Route to HR for verification before approval.';\n} else if (withinLimit && withinWindow && fraudScore < 30) {\n  decision = 'AUTO_APPROVE';\n  approvedAmount = claimAmount;\n  nextAction = `Auto-approved for ₹${claimAmount.toFixed(2)}. Process reimbursement within 3 business days.`;\n} else {\n  decision = 'REVIEW_REQUIRED';\n  approvedAmount = 0;\n  nextAction = 'Standard HR review required before approval.';\n}\n\n// ===== GENERATE CLAIM ID =====\n\nconst timestamp = new Date().toISOString().replace(/[-:T.]/g, '').substring(0, 14);\nconst claimId = `CLM-${timestamp}`;\n\n// ===== RETURN STRUCTURED DATA =====\n\nreturn {\n  Claim_ID: claimId,\n  Submission_Date: submissionDate,\n  Employee_Name: extracted.Employee_Name || 'NOT_FOUND',\n  Employee_ID: extracted.Employee_ID || 'NOT_FOUND',\n  Claim_Type: claimType,\n  Claim_Amount: `₹${claimAmount.toFixed(2)}`,\n  Policy_Limit: `₹${perClaimLimit.toFixed(2)}`,\n  Amount_Over_Limit: `₹${amountOverLimit.toFixed(2)}`,\n  Receipt_Date: treatmentDate,\n  Days_To_Submit: daysToSubmit,\n  Policy_Compliance: policyCompliance,\n  Fraud_Risk_Score: fraudScore,\n  Decision: decision,\n  Approved_Amount: `₹${approvedAmount.toFixed(2)}`,\n  Next_Action: nextAction,\n  \n  // Pass through for email\n  _full_claim_data: extracted,\n  _form_data: formData,\n  _approved_amount_numeric: approvedAmount,\n  _fraud_score: fraudScore,\n  _employee_email: extracted.Employee_Email || formData.field_3 || 'employee@company.com'\n};"
      },
      "id": "816611f3-2126-4203-a148-1106b61ce1e2",
      "name": "Policy Validation Engine",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        288,
        -160
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1fy9OUz8pG3Qk3M0iiGuxOpqUWMQWSH2--_ep9rM3hRQ",
          "mode": "list",
          "cachedResultName": "Case 53 - Employee Benefit Claim Log",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1fy9OUz8pG3Qk3M0iiGuxOpqUWMQWSH2--_ep9rM3hRQ/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1fy9OUz8pG3Qk3M0iiGuxOpqUWMQWSH2--_ep9rM3hRQ/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Claim_ID": "={{ $json.Claim_ID }}",
            "Submission_Date": "={{ $json.Submission_Date }}",
            "Employee_Name": "={{ $json.Employee_Name }}",
            "Employee_ID": "={{ $json.Employee_ID }}",
            "Claim_Type": "={{ $json.Claim_Type }}",
            "Claim_Amount": "={{ $json.Claim_Amount }}",
            "Policy_Limit": "={{ $json.Policy_Limit }}",
            "Amount_Over_Limit": "={{ $json.Amount_Over_Limit }}",
            "Receipt_Date": "={{ $json.Receipt_Date }}",
            "Days_To_Submit": "={{ $json.Days_To_Submit }}",
            "Policy_Compliance": "={{ $json.Policy_Compliance }}",
            "Fraud_Risk_Score": "={{ $json.Fraud_Risk_Score }}",
            "Decision": "={{ $json.Decision }}",
            "Approved_Amount": "={{ $json.Approved_Amount }}",
            "Next_Action": "={{ $json.Next_Action }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Claim_ID",
              "displayName": "Claim_ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Submission_Date",
              "displayName": "Submission_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Employee_Name",
              "displayName": "Employee_Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Employee_ID",
              "displayName": "Employee_ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Claim_Type",
              "displayName": "Claim_Type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Claim_Amount",
              "displayName": "Claim_Amount",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Policy_Limit",
              "displayName": "Policy_Limit",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Amount_Over_Limit",
              "displayName": "Amount_Over_Limit",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Receipt_Date",
              "displayName": "Receipt_Date",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Days_To_Submit",
              "displayName": "Days_To_Submit",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Policy_Compliance",
              "displayName": "Policy_Compliance",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Fraud_Risk_Score",
              "displayName": "Fraud_Risk_Score",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Decision",
              "displayName": "Decision",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Approved_Amount",
              "displayName": "Approved_Amount",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Next_Action",
              "displayName": "Next_Action",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "_full_claim_data",
              "displayName": "_full_claim_data",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "_form_data",
              "displayName": "_form_data",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "_approved_amount_numeric",
              "displayName": "_approved_amount_numeric",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "_fraud_score",
              "displayName": "_fraud_score",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            },
            {
              "id": "_employee_email",
              "displayName": "_employee_email",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "55a61e9c-db93-4c43-8fd9-474fa939e519",
      "name": "Log to Audit Database",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        480,
        -160
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.Decision }}",
                    "rightValue": "AUTO_APPROVE",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "308ead30-85a6-417b-94d6-3566f057376b"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "AUTO_APPROVE"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.Decision }}",
                    "rightValue": "REVIEW_REQUIRED",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "aac726b6-7657-4b2d-baf6-400bac2d6339"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "REVIEW_REQUIRED"
            }
          ]
        },
        "options": {
          "fallbackOutput": "none"
        }
      },
      "id": "43229add-4192-4e6e-bc57-3e2e0c8835c4",
      "name": "Decision Router",
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [
        720,
        -160
      ]
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json || {};\nconst claim = data._full_claim_data || {};\n\nconst emailSubject = `✅ Claim Approved - ${data.Approved_Amount || 'N/A'} | ${data.Claim_ID || 'Your Claim'}`;\nconst emailBody = `<html><body style=\"font-family:Arial,sans-serif;max-width:650px;margin:0 auto;padding:20px\"><div style=\"background:linear-gradient(135deg,#10b981,#059669);color:white;padding:25px;border-radius:8px;margin-bottom:20px\"><h1 style=\"margin:0;font-size:24px\">✅ Claim Approved</h1><p style=\"margin:5px 0 0 0\">Claim ID: ${data.Claim_ID || 'N/A'}</p></div><div style=\"background:#ecfdf5;border-left:4px solid #10b981;padding:15px;margin:20px 0;border-radius:4px\"><strong>Your claim has been approved!</strong></div><div style=\"background:#f9fafb;padding:20px;border-radius:8px;margin:20px 0\"><h2 style=\"margin:0 0 15px 0;font-size:18px\">Claim Details</h2><table style=\"width:100%\"><tr><td style=\"padding:8px 0;color:#6b7280\">Employee:</td><td style=\"padding:8px 0;font-weight:600\">${data.Employee_Name || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Claim Type:</td><td style=\"padding:8px 0\">${data.Claim_Type || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Claimed:</td><td style=\"padding:8px 0\">${data.Claim_Amount || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Approved:</td><td style=\"padding:8px 0;font-size:20px;color:#10b981;font-weight:700\">${data.Approved_Amount || 'N/A'}</td></tr></table></div><div style=\"background:#eff6ff;border:2px solid #3b82f6;border-radius:8px;padding:20px;margin:20px 0\"><h3 style=\"margin:0 0 10px 0;color:#1e40af\">Next Steps</h3><p style=\"margin:0\">${data.Next_Action || 'Payment will be processed.'}</p></div><div style=\"background:#f9fafb;padding:15px;text-align:center;margin-top:30px;border-top:2px solid #e5e7eb;font-size:13px;color:#6b7280\"><p style=\"margin:0\"><strong>Automated Claims System</strong></p><p style=\"margin:5px 0 0 0\">Generated: ${new Date().toLocaleString('en-IN',{timeZone:'Asia/Kolkata'})}</p></div></body></html>`;\n\nreturn {\n  emailSubject,\n  emailBody,\n  recipientEmail: data._employee_email || 'employee@company.com'\n};"
      },
      "id": "acb5d6da-5486-41fb-9121-82264b1d40fe",
      "name": "Build Approval Email",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        976,
        -272
      ]
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json || {};\nconst claim = data._full_claim_data || {};\n\nconst emailSubject = `⚠️ Claim Review Required | ${data.Claim_ID || 'Claim'}`;\nconst emailBody = `<html><body style=\"font-family:Arial,sans-serif;max-width:650px;margin:0 auto;padding:20px\"><div style=\"background:linear-gradient(135deg,#f59e0b,#d97706);color:white;padding:25px;border-radius:8px;margin-bottom:20px\"><h1 style=\"margin:0;font-size:24px\">⚠️ Review Required</h1><p style=\"margin:5px 0 0 0\">Claim ID: ${data.Claim_ID || 'N/A'}</p></div><div style=\"background:#fef3c7;border-left:4px solid #f59e0b;padding:15px;margin:20px 0;border-radius:4px\"><strong>Manual review needed</strong></div><div style=\"background:#f9fafb;padding:20px;border-radius:8px;margin:20px 0\"><h2 style=\"margin:0 0 15px 0;font-size:18px\">Details</h2><table style=\"width:100%\"><tr><td style=\"padding:8px 0;color:#6b7280\">Employee:</td><td style=\"padding:8px 0;font-weight:600\">${data.Employee_Name || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Type:</td><td style=\"padding:8px 0\">${data.Claim_Type || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Amount:</td><td style=\"padding:8px 0;font-weight:700\">${data.Claim_Amount || 'N/A'}</td></tr><tr><td style=\"padding:8px 0;color:#6b7280\">Reason:</td><td style=\"padding:8px 0\">${data.Next_Action || 'Review needed'}</td></tr></table></div></body></html>`;\n\nreturn {\n  emailSubject,\n  emailBody,\n  recipientEmail: data._employee_email || 'employee@company.com',\n  hrEmail: 'hr.benefits@company.com'\n};"
      },
      "id": "490bdad7-722f-4d1b-8f81-9aa67da84268",
      "name": "Build Review Email",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        992,
        -96
      ]
    },
    {
      "parameters": {
        "sendTo": "={{ $json.recipientEmail }}",
        "subject": "={{ $json.emailSubject }}",
        "message": "={{ $json.emailBody }}",
        "options": {}
      },
      "id": "c923b741-cc8e-4bad-9d6d-ec472ba7024b",
      "name": "Send Approval Email",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1232,
        -272
      ],
      "webhookId": "955af137-2f7a-472a-82ca-d5e63067ff46",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list"
        },
        "builtInTools": {},
        "options": {}
      },
      "id": "2700ba81-f21b-41c7-b4e3-ead0fabc2529",
      "name": "GPT-4o Mini",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        -32,
        32
      ],
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "sendTo": "={{ $json.recipientEmail }}",
        "subject": "={{ $json.emailSubject }}",
        "message": "={{ $json.emailBody }}",
        "options": {
          "ccList": "={{ $json.hrEmail }}"
        }
      },
      "id": "179e54b0-a6dd-457d-bf40-539623cd4f95",
      "name": "Send Review Email",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        1248,
        -96
      ],
      "webhookId": "2e72a70d-9570-499c-bb5e-c7c8d3b736ec",
      "credentials": {
        "gmailOAuth2": {
          "id": "cyqCGWcggZNMcSOv",
          "name": "Gmail account"
        }
      }
    }
  ],
  "pinData": {
    "Extract Claim Data": [
      {
        "json": {
          "output": {
            "Employee_Name": "Priya Sharma",
            "Employee_ID": "EMP-2891",
            "Department": "Software Engineering",
            "Employee_Email": "priya.sharma@company.com",
            "Contact_Number": "+91-9876543210",
            "Claim_Type": "Medical Reimbursement",
            "Treatment_Date": "2025-12-18",
            "Submission_Date": "2025-12-25",
            "Hospital_Clinic_Name": "Apollo Clinic, Koramangala, Bangalore",
            "Doctor_Name": "Dr. Rajesh Verma",
            "Patient_Name": "Priya Sharma",
            "Relationship_To_Employee": "Self",
            "Reason_For_Treatment": "Routine health check-up and blood tests",
            "Total_Claimed_Amount": "5450",
            "Number_Of_Receipts": "3"
          }
        }
      }
    ]
  },
  "connections": {
    "Claim Submission Form": {
      "main": [
        [
          {
            "node": "Upload Claim Document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload Claim Document": {
      "main": [
        [
          {
            "node": "Wait for Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait for Parsing": {
      "main": [
        [
          {
            "node": "Check Parsing Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check Parsing Status": {
      "main": [
        [
          {
            "node": "Status Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Status Router": {
      "main": [
        [
          {
            "node": "Get Parsed Claim Data",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Wait for Parsing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Parsed Claim Data": {
      "main": [
        [
          {
            "node": "Extract Claim Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Claim Data": {
      "main": [
        [
          {
            "node": "Policy Validation Engine",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Policy Validation Engine": {
      "main": [
        [
          {
            "node": "Log to Audit Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Log to Audit Database": {
      "main": [
        [
          {
            "node": "Decision Router",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Decision Router": {
      "main": [
        [
          {
            "node": "Build Approval Email",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Build Review Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Approval Email": {
      "main": [
        [
          {
            "node": "Send Approval Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build Review Email": {
      "main": [
        [
          {
            "node": "Send Review Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GPT-4o Mini": {
      "ai_languageModel": [
        [
          {
            "node": "Extract Claim Data",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "12090010-e719-471e-b2bc-fa9dbed4ebaf",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "7JXsWzgOHpyXfxSw",
  "tags": []
}